package com.ruoyi.project.sell.order.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.sell.order.domain.SellOrder;
import com.ruoyi.project.sell.order.mapper.SellOrderMapper;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * @author syb date 2020/9/18
 */
@Service
public class SellOrderServiceImpl implements ISellOrderService{

  @Autowired
  private SellOrderMapper sellOrderMapper;

  @Override
  public List<SellOrder> selectSellOrderList(SellOrder sellOrder) {
    return sellOrderMapper.selectSellOrderList(sellOrder);
  }

  @Override
  public String checkSellOrderNameUnique(SellOrder sellOrder) {
    Long sellOrderId = StringUtils.isNull(sellOrder.getSellOrderId()) ? -1L : sellOrder.getSellOrderId();
    SellOrder info = sellOrderMapper.checkSellOrderNameUnique(sellOrder.getSellOrderName());
    if (StringUtils.isNotNull (info) && info.getSellOrderId().longValue() != sellOrderId.longValue())
    {
      return UserConstants.SELL_ORDER_NAME_NOT_UNIQUE;
    }
    return UserConstants.SELL_ORDER_NAME_UNIQUE;
  }

  @Override
  public int insertSellOrder(SellOrder sellOrder) {
    return sellOrderMapper.insertSellOrder(sellOrder);
  }

  @Override
  public SellOrder selectSellOrderById(Long sellOrderId) {
    return sellOrderMapper.selectSellOrderById(sellOrderId);
  }

  @Override
  public int updateSellOrder(SellOrder sellOrder) {
    return sellOrderMapper.updateSellOrder(sellOrder);
  }

  @Override
  public int deleteSellOrderIds(String ids) {
    Long[] orderIds = Convert.toLongArray(ids);
    return sellOrderMapper.deleteSellOrderIds(orderIds);
  }
}
